<template>
  <div class="divBox">
    <el-card class="box-card">
      <el-form inline size="small" @submit.native.prevent>
        <el-form-item label="处理单位：">
          <el-select v-model="listPram.departmentId" placeholder="请选择">
            <el-option
                v-for="item in hearList1"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="灾害种类：">
          <el-select v-model="listPram.type" placeholder="请选择">
            <el-option
                v-for="item in type"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="理赔状态：">
          <el-select v-model="listPram.claimsSettlementStatus" placeholder="请选择">
            <el-option
                v-for="item in statusList"
                :key="item.id"
                :label="item.name"
                :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button icon="el-icon-search" size="mini" type="primary" @click.native="getList">搜索</el-button>
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
        </el-form-item>
      </el-form>
      <el-table :data="listData.list" size="mini" :header-cell-style=" {fontWeight:'bold',background:'#f8f8f9',color: '#515a6e',height:'40px'}" border>
        <el-table-column label="ID" prop="id" width="60" ></el-table-column>
        <el-table-column label="状态" prop="allocationStatus" min-width="50" >
          <template slot-scope="scope">
            <div style="color:dodgerblue;" v-if="scope.row.statusText==='已分配'">{{scope.row.statusText}}</div>
            <div style="color:yellowgreen;" v-if="scope.row.statusText==='待分配'">{{scope.row.statusText}}</div>
            <div style="color:#FF8D02;" v-if="scope.row.statusText==='已办结'">{{scope.row.statusText}}</div>
            <div style="color:dodgerblue;" v-if="scope.row.statusText==='已处理'">{{scope.row.statusText}}</div>
            <div style="color:#FF8D02;" v-if="scope.row.statusText==='待处理'">{{scope.row.statusText}}</div>
          </template>
        </el-table-column>
        <el-table-column label="处理单位" prop="realName"/>
        <el-table-column label="昵称" prop="username"/>
        <el-table-column label="电话" prop="phone"/>
        <el-table-column label="种类" prop="typeText"/>
        <el-table-column label="村组" prop="areaName"/>
        <el-table-column label="位置" prop="position" width="170"/>
        <el-table-column label="具体位置" prop="specificPosition" min-width="120"/>
        <el-table-column label="灾害情况" prop="disasterSituation" min-width="180"/>
        <el-table-column label="发生时刻" prop="occurTime" min-width="120"/>
        <el-table-column label="是否匿名" align="center">
          <template slot-scope="scope">
            <div v-if="scope.row.isAnonymous === 1">是</div>
            <div v-if="scope.row.isAnonymous === 2">否</div>
          </template>
        </el-table-column>
        <el-table-column label="操作" min-width="240" fixed="right" align="center">
          <template slot-scope="scope">
            <el-button icon="el-icon-set-up" type="success" size="mini" @click="setDeal2(scope.row)" v-show="scope.row.allocationStatus===1" v-has-permi="['admin:disaster:allot']">分配</el-button>
            <el-button icon="el-icon-s-cooperation" size="mini" type="success" @click="openEdit1(scope.row.id,scope.row)" v-show="scope.row.allocationStatus===2" v-has-permi="['admin:disaster:dispose']">处理</el-button>
            <el-button icon="el-icon-s-cooperation" size="mini" type="warning" @click="openEdit2(scope.row.id,scope.row)" v-show="scope.row.allocationStatus===3" v-has-permi="['admin:disaster:claimsSettlement']">理赔</el-button>
            <el-button icon="el-icon-edit" size="mini" type="primary" @click="openEdit(scope.row.id)"  v-has-permi="['admin:disaster:detail']">详情</el-button>
            <el-button icon="el-icon-delete" size="mini" type="danger" @click="handlerDelete(scope.row.id)"  v-has-permi="['admin:disaster:delete']">删除</el-button>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
          :current-page="listPram.page"
          :page-sizes="[20,40,60,80,100]"
          layout="total, sizes, prev, pager, next, jumper"
          :total="listData.count"
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
      />
    </el-card>
    <el-dialog
        :visible.sync="editDialog.show"
        title="详情"
        destroy-on-close
        :close-on-click-modal="false"
        width="800px"
        top="80px">
      <edit
          v-if="editDialog.show"
          :id="editDialog.id"
          @hideEditDialog="hideEditDialog"
          ref="editForm"
      />
    </el-dialog>
    <el-dialog
        :visible.sync="editDialog1.show"
        title="处理"
        destroy-on-close
        :close-on-click-modal="false"
        width="1500px">
      <edit1
          v-if="editDialog1.show"
          :id="editDialog1.id"
          :statu="editDialog1.statu"
          @hideEditDialog="hideEditDialog1"
          ref="editForm"
      />
    </el-dialog>
    <el-dialog
        :visible.sync="editDialog2.show"
        title="理赔"
        destroy-on-close
        :close-on-click-modal="false"
        width="800px">
      <edit3
          v-if="editDialog2.show"
          :id="editDialog2.id"
          :status="editDialog2.status"
          @hideEditDialog="hideEditDialog2"
          ref="editForm"
      />
    </el-dialog>
    <el-dialog width="50%"  v-if="dialogVisible3" :visible.sync="dialogVisible3" title="分发" :close-on-click-modal="false"
               :close-on-press-escape="false" :destroy-on-close="true"
    >
      <Edit2 ref="detail" :id="id"  :Close3="Close3"></Edit2>
      <span slot="footer" class="dialog-footer" v-if="adminUserId==1">
        <el-button type="primary" class="primary" @click="$refs.detail.distribute(id)">确 定</el-button>
      </span>
      <span slot="footer" class="dialog-footer" v-else-if="adminUserId==2 || adminUserId==3">
        <el-button type="primary" class="primary" @click="$refs.detail.distribute(id)"  :disabled="true">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import edit from './edit'
import {deleteRow, list, updateStatus,getTypeListApi} from "@/api/disaster";
import {checkPermi} from "@/utils/permission";
import edit1 from '@/views/disaster/edit1.vue';
import Edit2 from '@/views/disaster/edit2.vue';
import * as disasterApi from "@/api/disaster";
import Edit3 from "@/views/disaster/edit3.vue";
export default {
  components: {Edit3, edit,edit1,Edit2 },
  data() {
    return {
      adminUserId:0,
      listData: { list: [],count:0 },
      listPram: {
        claimsSettlementStatus:'',
        departmentId:null,
        type: '',
        page: 1,
        limit: 20,
      },
      id:0,
      dialogVisible3: false,//分配dialog
      dialogVisible4: false,//处理dialog
      editDialog:{
        show:false,
        id:null
      },
      editDialog1:{
        show:false,
        id:null,
        status:null
      },
      editDialog2:{
        show:false,
        id:null,
        status:null
      },
      tableLoading:false,
      type:[],
      hearList1:[],
      statusList:[{id:0,name:"未处理"},{id:1,name:"已理赔"},{id:2,name:"未理赔"}]
    }
  },
  mounted() {
    this.getList()
    this.getTypeList()
    this.selectReviewRoom()
  },
  methods: {
    checkPermi,
    getTypeList(){
      getTypeListApi().then(res=>{
        this.type=res;
      })
    },
    selectReviewRoom() {
      this.hearListLoading = true
      disasterApi.list1().then(res => {
        this.hearList1 = res.list
      }).finally(()=>{
        this.hearListLoading = false
      })
    },
    getList(){
      this.tableLoading=true
     list(this.listPram,).then(res=>{
        this.listData.list=res.list;
      this.listData.count=res.count;
      }).finally(()=>{})
      this.tableLoading=false;
    },
    Close3() {
      this.dialogVisible3 = false
      this.getList()
    },
    Close4() {
      this.dialogVisible4 = false
      this.getList()
    },
    setDeal2(row){
      this.dialogVisible3 = true
      this.id = row.id;
      this.adminUserId = row.allocationStatus
    },
    openEdit(id=null){
      this.editDialog.id=id;
      this.editDialog.show=true
    },
    openEdit1(id=null,row){
      this.editDialog1.status = row.allocationStatus
      this.editDialog1.id=id;
      this.editDialog1.show=true
    },
    openEdit2(id=null,row){
      this.editDialog2.status = row.claimsSettlementStatus
      this.editDialog2.id=id;
      this.editDialog2.show=true
    },
    handlerDelete(id) {
      this.$confirm('确认删除该数据吗？').then(() => {
        const loading=this.$loading({text:'删除中',background:'rgba(255,255,255,.5)'})
        deleteRow(id).then(() => {
          this.$message.success('删除成功')
          this.getList()
        }).finally(()=>{
          loading.close()
        })
      })
    },
    hideEditDialog() {
      this.editDialog.show = false
      this.getList()
    },
    hideEditDialog1() {
      this.editDialog1.show = false
      this.editDialog2.show = false
      this.getList()
    },
    hideEditDialog2() {
      this.editDialog2.show = false
      this.getList()
    },
    handleSizeChange(val) {
      this.listPram.limit = val
      this.getList()
    },
    handleCurrentChange(val) {
      this.listPram.page = val
      this.getList()
    },
    handleStatusChange(status,id){
      const loading=this.$loading({text:'更新中',background:'rgba(255,255,255,.5)'})
      updateStatus(id,status).then(()=>{
        this.$message.success('更新状态成功')
        this.getList()
      }).finally(()=>{
        loading.close()
      })
    },
    resetQuery(){
      this.listPram.keyword = '';
      this.listPram.type = '';
      this.listPram.claimsSettlementStatus = '';
      this.listPram.departmentId = null
      this.getList()
    }
  }
}
</script>

<style scoped lang="scss">
.fixed-height-dialog .el-dialog__body {
  max-height: 800px; /* 你想要设置的固定高度 */
  overflow-y: auto; /* 添加滚动条，以便在内容溢出时滚动 */
}
</style>
